<template>
  <div class="_wz_cent_main _wz_problemProcessing">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="上报人">
          <i-input v-model="formDataSearch.userName" placeholder="请填写上报人" clearable />
        </FormItem>
        <FormItem label="处理状态">
          <i-select v-model.number="formDataSearch.reportStatus" filterable placeholder="请选择处理状态" clearable>
            <Option :value="0">未处理</Option>
            <Option :value="1">已处理</Option>
          </i-select>
        </FormItem>
        <FormItem label="处理人" v-if="searchType">
          <i-input v-model="formDataSearch.toManagerName" placeholder="请填写处理人" clearable />
        </FormItem>
        <FormItem label="上报日期" v-if="searchType">
          <DatePicker type="daterange" v-model="dateRange" placeholder="请选择上报日期" style="width:96%"></DatePicker>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>


    <Drawer title="详情" v-model="formOperation" width="900" :mask-closable="false" :draggable="true">
      <problemProcessingDetails v-if="formOperation" :selectData="selectData" @closeFun="closeFun"></problemProcessingDetails>
    </Drawer>

  </div>
</template>
<script>


import wzTbale from "../../../components/table/table";
import problemProcessingDetails from "./problemProcessingDetails";

export default {
  components: {
    wzTbale,//列表
    problemProcessingDetails,
  },
  data() {
    return {
      dateRange: [],
      searchType:false,//搜索条件
      subDeptList: [],//运输企业
      selectData: {},//
      formDataSearch: {},//搜索表单数据
      formOperation: false,//表单左侧移出
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },

      tableData: {
        url: this.apiUrl.safetyProblemReportAllReportList,//请求地址
        method: 'post',//请求方式
        where: {},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '上报人', minWidth: 100, key: 'userName'},
          {title: '上报内容', minWidth: 160, key: 'reportContent'},
          {title: '指定处理人', minWidth: 120, key: 'toManagerName'},
          // {title: '企业部门', minWidth: 120, key: 'managerOrgName'},
          {title: '上报时间', minWidth: 160, key: 'reportTime'},
          {title: '处理状态', minWidth: 140,fixed: 'right', render: (h, params) => {
              var color = '', test = '';
              if (params.row.reportStatus == 0) {
                color = 'error', test = '未处理';
              }else {
                color = 'primary', test = '已处理';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },
          {title: '运输企业', minWidth: 260, key: 'deptName'},
          {
            title: '操作', fixed: 'right', width:120,
            render: (h, params) => {
              var operationButtons = [];

              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = params.row;
                      this.formOperation = true;
                    }
                  }
                }, "查看")
              )


              operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.removeTableFun(params.row);
                    }
                  }
                }, "删除")
              )
              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },

    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    var that = this;

    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })



  },
  methods: {//执行的方法
    removeTableFun(data) {//删除
      let that = this;
      that.$Modal.confirm({
        title: '删除提醒',
        content: '确定要删除选中的记录？',
        onOk: () => {
          that.spinShow = true;
          that.axios.post(that.apiUrl.safetyProblemReportDelete, {uuid: data.uuid}).then(res => {
            that.spinShow = false;
            if (!!res) {
              that.$Message.success('数据删除成功.');
              that.$refs.wzTbale.tableLoadData();
            }
          }).catch(err => {
            console.log("失败", err)
          })
        },
        onCancel: () => {
          //点击取消
        }
      });
    },
    searchSubmit() {//搜索
      this.formDataSearch.reportTimeStart = !!this.dateRange[0] ? this.public.timeFormatting(this.dateRange[0], "yyyy-MM-dd") : '';
      this.formDataSearch.reportTimeEnd = !!this.dateRange[1] ? this.public.timeFormatting(this.dateRange[1], "yyyy-MM-dd") : '';
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.formOperation = false;
    },

  },
  watch: {//监听

  },
  props: {//接收来自父组件的数据

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_problemProcessing {
  display: flex;
  flex-direction: column;


}
</style>
